<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTaskTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('task', function (Blueprint $table) {
            $table->increments('id');

            $table->enum('enabled', ['true', 'false'])->default('true')->comment('任务是否关闭');

            $table->string('user_id', 20)->default('')->comment('用户ID');
            $table->string('shop_id', 20)->default('')->comment('该规则商户ID');

            $table->string('order_num')->default('')->comment('订单号');
            $table->json('pistolgraph')->default('')->comment('积分规则快照 json 格式');
            $table->enum('type', ['day', 'luck', 'manual'])->default('day')->comment('红包类型:day天天红包|luck幸运红包|manual手动任务');
            $table->integer('count')->default(0)->comment('剩余天天红包积分数|幸运红包个数');
            $table->decimal('grant_integral', 38, 4)->default(0)->comment('已经发放的积分');
            $table->decimal('unissued_integral', 38, 4)->default(0)->comment('未发放的积分');
            $table->enum('disable', ['true', 'false'])->default('false')->comment('是否开启');
            $table->integer('create_time')->default(0)->comment('创建时间');
            $table->integer('update_time')->default(0)->comment('更新时间');

            // 索引
            $table->index('shop_id');
            $table->index('user_id');
            $table->index('order_num');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('task');
    }
}
